# import subprocess
# from django.http import JsonResponse
#
#
# class ErrorHandlingMiddleware:
#     def __init__(self, get_response):
#         self.get_response = get_response
#
#     def __call__(self, request):
#         try:
#             response = self.get_response(request)
#         except Exception as e:
#             # 捕获异常并重启容器
#             container_name = "my_container"
#             restart_command = f"docker restart {container_name}"
#             subprocess.run(restart_command, shell=True)
#
#             # 返回一个错误响应
#             return JsonResponse({"error": str(e)}, status=500)
#         return response
